package com.wkk.nursinghome.dao;

import com.wkk.nursinghome.domain.Bedstaff;
import com.wkk.nursinghome.domain.Employee;
import org.apache.ibatis.jdbc.SQL;

public class BedstaffSQLProvider {
    public String updateBedstaff(Bedstaff bedstaff){
        return new SQL(){
            {
                UPDATE("bedstaff");
                if(null!=bedstaff.getFnumber()){
                    SET("fnumber=#{fnumber}");
                }
                if(null!=bedstaff.getName()){
                    SET("name=#{name}");
                }
                if(null!=bedstaff.getSex()){
                    SET("sex=#{sex}");
                }
                if(null!=bedstaff.getStusetime()){
                    SET("stusetime=#{stusetime}");
                }
                if(null!=bedstaff.getEnusetime()){
                    SET("enusetime=#{enusetime}");
                }
                if(null!=bedstaff.getBedtails()){
                    SET("bedtails=#{bedtails}");
                }
                WHERE("id=#{id}");
            }
        }.toString();
    }
    //根据条件查询信息
    public String selectBedstaffByCondition(Bedstaff bedstaff){
        return new SQL(){
            {
                SELECT("*");
                FROM("bedstaff");
                //使用动态SQL拼接查询条件
                if(null!=bedstaff.getName()){
                    WHERE("name like concat('%',#{name},'%')");
                }
                if(null!=bedstaff.getFnumber()){
                    WHERE("fnumber=#{fnumber}");
                }
            }
        }.toString();
    }
}
